const MessageModel = require('../models/messageModel');

class MessageController {
    // ... existing code ...

    // 删除聊天记录
    static async deleteMessages(req, res) {
        try {
            const { senderId, recipientId, isRead } = req.body;

            // 验证必要参数
            if (!senderId || !recipientId) {
                return res.status(400).json({
                    status: 'error',
                    message: '发送者ID和接收者ID是必需的'
                });
            }

            // 验证用户权限
            if (req.user.id != senderId && req.user.id != recipientId) {
                return res.status(403).json({
                    status: 'error',
                    message: '您没有权限删除这些聊天记录'
                });
            }

            const result = await MessageModel.deleteMessages(senderId, recipientId, isRead);

            res.status(200).json({
                status: 'success',
                message: '聊天记录已删除',
                data: {
                    affectedRows: result.affectedRows
                }
            });
        } catch (error) {
            res.status(500).json({
                status: 'error',
                message: error.message
            });
        }
    }
}

module.exports = MessageController; 